package com.jcroke.kestrel.feather_1;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import net.lag.kestrel.thrift.Item;

import org.apache.thrift7.TException;

import backtype.storm.spout.KestrelThriftClient;

public class KestrelUtil {

	static final int EXPIRATION = 10000;

	@SuppressWarnings("unused")
	private static void queueItems(KestrelThriftClient kestrelClient,
			String queueName) {
		Random rand = new Random();

		ByteBuffer bBuf = ByteBuffer.allocateDirect(16);
		bBuf.clear();
		List<ByteBuffer> items = null;

		try {
			kestrelClient.put("hercules", items, EXPIRATION);
		} catch (TException e) {
			e.printStackTrace();
		}
	}

	@SuppressWarnings("unused")
	private static void dequeueAndRemoveItems(
			KestrelThriftClient kestrelClient, String queueName) {

		List<Item> dequ = new ArrayList<Item>();
		Byte[] dataBuf = new Byte[4096];

		try {
			dequ = kestrelClient.get("hercules", 10, 5000, 10000);
		} catch (TException e) {
			e.printStackTrace();
		}

		if (dequ == null) {
			System.out.println("The queue (" + queueName
					+ ") contains no items.");
		} else {
			for (Item i : dequ) {
				i.get_data();
			}
		}

	}
}